package com.cookie.libgdx.airforcecolonel.sprite;

import com.badlogic.gdx.math.Vector2;


public class Plane extends DynamicGameObject{
	private final float maxOil; // the max oil set
	private final float fuelConsumption; //the oil lost per delta time
	private final int armoring; //the max hit
	private float bulletVelocity;//the bullet Velocity 
	private int bulletNumber;//the bullet Number
	private int bombNumber; //the bomb number
	private int stopBullentTimes;//current hit
	private float oil;//current oil
	
	private final float targetLength;
	
	public Plane(float x, float y, float width, float height,float targetLength,float bullentVelocity,float maxOil,float fuelConsumption,int armoring) {
		super(x, y, width, height);
		this.targetLength = targetLength;
		this.bulletVelocity = bullentVelocity;
		this.stopBullentTimes = 0;
		this.maxOil = maxOil;
		this.fuelConsumption = fuelConsumption;
		this.armoring = armoring;
	}
	
	public float setOil(float oil){
		if(oil> this.maxOil){
			this.oil = this.maxOil;
			return oil-this.oil;
		}else{
			this.oil = oil;
			return 0;
		}
	}
	
	public boolean isHit(Vector2 bullent){
		float hit=bullent.len2()- targetLength*targetLength;
		if(hit<0){
			return true;
		}else{
			return false;
		}
	}
	
	public void update(float deltaTime){
		this.positon.add(this.velocity.x*deltaTime,this.velocity.y*deltaTime);
		this.velocity.add(this.accel.x*deltaTime,this.accel.y*deltaTime);
		this.oil = this.oil - this.fuelConsumption*deltaTime;
 	}
	
	public Bullent shot(){
		if(this.bulletNumber<=0){
			return null;
		}
		Bullent bullent = new Bullent(this.positon.x, this.positon.y, 10, 10);
		float scale =(float) (this.bulletVelocity/this.velocity.len());
		bullent.velocity.set(this.velocity);
		bullent.velocity.mul(scale);
		this.bulletNumber--;
		return bullent;
	}
	
	public Bomb throwBomb(){
		if(this.bombNumber <= 0){
			return null;
		}
		Bomb bomb= new Bomb(this.positon.x, this.positon.y, 10, 10);
		bomb.velocity.x = this.velocity.x;
		bomb.velocity.y = this.velocity.y;
		this.bombNumber--;
		return bomb;
	}
	
	public void setBombNumber(int bombNumber){
		this.bombNumber = bombNumber;
	}
	
	public void setBulletNumber(int bulletNumber){
		this.bulletNumber = bulletNumber;
	}
	
	public float hitLevel(){
		return this.stopBullentTimes/this.armoring;
	}
	
	public void change(Vector2 f){
		this.accel.add(f);
	}

	@Override
	public String toString() {
		return "V:"+this.velocity.toString()+" P:"+this.velocity.toString();
	}
	
	
}
